package com.neuralnoise.hibernate.liveJournal;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.MappedSuperclass;

@MappedSuperclass
public abstract class AbstractJournal implements java.io.Serializable {

	private static final long serialVersionUID = 7189809495413245085L;

	private String id;
	
	private Set<Interest> interests = new HashSet<Interest>(0);
	
	private Set<Journal> journalsForSubject = new HashSet<Journal>(0);
	private Set<Journal> journalsForObject = new HashSet<Journal>(0);

	public AbstractJournal() { }

	public AbstractJournal(String id) {
		this.id = id;
	}

	public AbstractJournal(String id, Set<Interest> interests, Set<Journal> journalsForSubject, Set<Journal> journalsForObject) {
		this.id = id;
		this.interests = interests;
		this.journalsForSubject = journalsForSubject;
		this.journalsForObject = journalsForObject;
	}

	@Id
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "LiveJournalHasInterest", joinColumns = { @JoinColumn(name = "journal", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "interest", nullable = false, updatable = false) })
	public Set<Interest> getInterests() {
		return this.interests;
	}

	public void setInterests(Set<Interest> interests) {
		this.interests = interests;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "journalsForObject")
	public Set<Journal> getJournalsForSubject() {
		return this.journalsForSubject;
	}

	public void setJournalsForSubject(Set<Journal> journalsForSubject) {
		this.journalsForSubject = journalsForSubject;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "LiveJournalFriendOf", joinColumns = { @JoinColumn(name = "subject", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "object", nullable = false, updatable = false) })
	public Set<Journal> getJournalsForObject() {
		return this.journalsForObject;
	}

	public void setJournalsForObject(Set<Journal> journalsForObject) {
		this.journalsForObject = journalsForObject;
	}

}